package com.zsj.juc.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author <a href="https://gitee.com/zhengshengjun">zsj</a>
 * @date 2023/12/7.
 */
@Slf4j
public class Test7 {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (true) {
                boolean interrupted = Thread.currentThread().isInterrupted();
                if (interrupted) {
                    log.debug("线程{}被其它线程要求打断,退出循环....", Thread.currentThread().getName());
                    break;
                }
            }
        }, "t1");
        t1.start();
        log.debug("{}线程要求{}线程打断运行", Thread.currentThread().getName(), t1.getName());
        t1.interrupt();
    }
}
